package com.cjj.annotation;

import java.lang.annotation.Annotation;
import java.lang.reflect.Field;

/**
 * @ClassName ZhujieFanshe
 * @Date 2021/07/28 11:39:30
 * @Created by ccc-j
 * @email ccc-ju@outlook.com
 */
public class ZhujieFanshe {

    public static void main(String[] args) throws ClassNotFoundException {
        // 利用反射操作注解
        Class<?> aClass = Class.forName("com.cjj.annotation.UserEntity");
        // getAnnotations该类上用到了哪些注解
        Annotation[] annotations = aClass.getAnnotations();
        SecTable secTable = aClass.getAnnotation(SecTable.class);
        Field[] declaredFields = aClass.getDeclaredFields();
        StringBuffer sb = new StringBuffer();
        sb.append(" select ");
        for(int i = 0; i < declaredFields.length; i++){
            SecProperty secProperty = declaredFields[i].getAnnotation(SecProperty.class);
            String property = secProperty.name();
            sb.append(property);
            if(i == declaredFields.length - 1){
                sb.append(" from ");
            }else {
                sb.append( " ,");
            }
        }
        /*for(Annotation annotation : annotations){
            System.out.println(annotation);
        }*/
        // tableValue
        String value = secTable.value();
        //System.out.println(value);
        // 生成ORM框架 SQL语句
        sb.append(" " + value + ";");
        System.out.println(sb.toString());
    }

}
